import 'dart:convert';

import 'package:flutter_book/data/model/yck/rule/rule.dart';


class TocRule {
  Rule? chapterList;
  Rule? chapterName;
  Rule? chapterUrl;
  Rule? isVip;
  Rule? updateTime;
  Rule? nextTocUrl;


  TocRule(this.chapterList, this.chapterName, this.chapterUrl, this.isVip, this.updateTime, this.nextTocUrl);

  TocRule.fromJson(dynamic json) {
    json = checkJson(json);
    chapterList = json['chapterList'];
    chapterName = json['chapterName'];
    chapterUrl = json['chapterUrl'];
    isVip = json['isVip'];
    updateTime = json['updateTime'];
    nextTocUrl =json['nextTocUrl'];
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map['chapterList'] = chapterList;
    map['chapterName'] = chapterName;
    map['chapterUrl'] = chapterUrl;
    map['isVip'] = isVip;
    map['updateTime'] = updateTime;
    map['nextTocUrl'] = nextTocUrl;
    return map;
  }


  Map<String,dynamic> checkJson(dynamic jsonString){
    if (jsonString == null) {
      jsonString =Map();
    }else if(jsonString is String){
      try{
        jsonString = json.decode(jsonString);
        if(!(jsonString is Map<String,dynamic>)){
          jsonString =Map();
        }
      }catch (e){
        jsonString =Map();
      }
    }else if(jsonString is TocRule){
      jsonString = jsonString.toJson();
    }else if(!(jsonString is Map<String,dynamic>)){
      jsonString =Map();
    }
    return jsonString;
  }

}
